home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Paging program
- Date: 12 Mar 1996 13:16:46 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4i4pjuINN72c@keats.ugrad.cs.ubc.ca>
- References: <Do5ABu.1v0@matt.fidalgo.net>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <Do5ABu.1v0@matt.fidalgo.net>,
- Matt Gischer <matt@matt.fidalgo.net> wrote:
- >I'm trying to get this program here to work. It's supposed to take a
- >file (from stdin or the command line) and pause every 24 lines.
-
- Boy, and I thought you were going to ask an off topic question about
- implemending a demand paging virtual memory scheme. Silly me...
-
- >(although i'd like some insight on how to find out how many rows the
- >users terminal has). Anyway.. this thing prints out the last line of the
-
- There is a way of doing this in UNIX. First of all, you can query the LINES
- environment variable using getenv(). Secondly, you can retrive a special
- structure from the terminal driver that has the rows and columns info via a
- special ioctl(). The SIGWINCH signal can be delivered to your process when the
- terminal size changes, at which point you re-read the structure. But that is a
- subject for comp.unix.programmer...
-
- >file however many lines it is short of a full page on the last page.
- >So.. i was wondering if anyone could help me with that. Thanks.
- >
- >#include <stdio.h>
- >
- >main(int argc, char *argv[])
- >{
- >FILE *in;
- >char t[80],enter;
- >int x=0,z=0,s=0,y=0;
- >if((in=fopen(argv[1], "r"))==NULL) {
- >in=stdin;
- >}
- >while(!feof(in)) {
- >fgets(t, 79,in);
- >x++;
- >}
- >x--;
- >rewind(in);
- >y=x/24;
- >if((y*24)<x) {
- >y++;
- >}
- >for(s=0;s<y;s++) {
- > for(z=0;z<24;z++) {
- > fgets(t,79,in);
- > if(t!=NULL) {
- > print(t);
- > }
- > }
- > if(x>=24) {
- > printf("Hit enter for more");
- > enter=getchar();
- >}
- >}
- >fclose(in);
- >return 0;
- >}
-
- Boy, someone needs practice! How about:
-
- int count = 0;
-
- while(1) {
- /* read line from file */
- /* if end of file, exit */
- if (++count > 23) {
- count = 0;
- /* prompt for enter */
- }
- }
-
- Another way is to start with a counter of 1, and test its divisibility by 24
- using the modulo operator (%).
-
- Do you realize that your if (t!=NULL) test will never succeed because the
- expression t gives the address of the first element of the t array, an address
- that never changes? Why are you using a zillion variables for such a simple
- 3roblem? You're not writing a compiler!
- --
-
-